import axios from 'axios';
import store from '@/store';
import { Toast } from 'antd-mobile';
export default {
    getTopList (dispatch) {
        axios.get('http://api.shujuzhihui.cn/api/news/categories?appKey=6c9c8e0c90a3456999b548dc8629ea70')
          .then(data => {
            // console.log(data.data)
            if (data.data.RESULT.length !== 0) {
              dispatch({
                  type:'CHANGE_TOPLIST',
                  data: data.data.RESULT
              })
            }
          })
      },
    updateList (dispatch) {
      let category = store.getState().home.title
      let page = store.getState().home.page || 1
      axios.get(`http://api.shujuzhihui.cn/api/news/list?appKey=6c9c8e0c90a3456999b548dc8629ea70&category=${category}&page=${page}`
      ).then(data => {
        // console.log(data.data.RESULT.newsList)
        dispatch({
          type:'UPDATE_LIST',
          data:data.data.RESULT
        })
        Toast.hide()
      })
    }
}